<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="pu" uri="/WEB-INF/tld/pageutil.tld" %>
<%@taglib prefix="mu" uri="/WEB-INF/tld/mallutil.tld" %>
<%@taglib prefix="pageable" uri="/WEB-INF/tld/pageable.tld" %>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
${pu:reqSet('nmHql', 'from AddOnProduct where mainProductId=? and addOnPrice!=? and isEnable=? and isDelete!=?') }
${pu:reqSet('params', null) }
${pu:listAdd('params', param.productId) }
${pu:listAdd('params', pu:toLong(0)) }
${pu:listAdd('params', 'Y') }
${pu:listAdd('params', 'Y') }
${pu:reqSet('addOnProducts', pu:queryByHql(nmHql, pu:arrayGet('params'), null)) } 
<!-- mn --> 
<div class="pdnm">
	<p class="pdnmtitle">任选<b> ${product.pickupQty} </b>件 <b>
		<c-rt:if test="${!empty shelfs[0].shelfPrice}">${pu:currency(shelfs[0].shelfPrice)}</c-rt:if></b>
	</p>
	<div class="pdnmpbox"> 
  	<c-rt:forEach items="${addOnProducts}" var="addOnProduct" varStatus="nmStatus">
      <c-rt:set var="aoproduct" value="${pu:get('com.yaodian100.ec.product.entity.Product', addOnProduct.addOnProductId)}"/>
      <c-rt:set var="url">/product/addOnProductInfo.do?productId=${product.productId }&addOnProductId=${addOnProduct.addOnProductId }</c-rt:set>
			<c-rt:set var="inventorySum" value="0"/>
	      <c-rt:forEach items="${aoproduct.specifications}" var="spec">
	      	<c-rt:if test="${spec.isDelete=='N'}">
	      		<c-rt:set var="nmClassName" value="pdnmpinnerboxbg-out"/>
	          <c-rt:set var="parasSpecInventory" value="${null}"/>
						<c-rt:set var="paramsSpecInventory" value="${pu:addToList('parasSpecInventory', spec.specificationId)}"/>
						<c-rt:set var="specInventorys" value="${pu:queryByHql('from SpecificationInventory where specId=?', paramsSpecInventory, null)}"/>
						${pu:listAdd('nmSpecInventorys', specInventorys[0].inventory)}
						<c-rt:set var="inventorySum">${inventorySum + specInventorys[0].inventory}</c-rt:set>
					</c-rt:if>
			</c-rt:forEach>
			<c-rt:if test="${inventorySum>0}">
				<c-rt:set var="hasInventory" value="true"/>
				<c-rt:set var="nmClassName" value="pdnmpinnerboxbg"/>
			</c-rt:if>
			<c-rt:if test="${inventorySum ==0}">
				<c-rt:set var="hasInventory" value="false"/>
			</c-rt:if>
      <div class="${nmClassName}" id="${nmClassName}_${nmStatus.index}">
      	<c-rt:url value="/product/nmDetail.do?productId=${aoproduct.productId}&nmProductId=${product.productId}&index=${nmStatus.index}" var="urlPath"/>
      	<a href="javascript:;" onClick="window.open('${urlPath}','','weight=780,height=600,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,left=50,top=50');return false;">
      		<img src="/PImg/${pu:substring(addOnProduct.addOnProductId, 0,4)}/${addOnProduct.addOnProductId}/${addOnProduct.addOnProductId }_m135.jpg" onError="this.src='/PImg/blank_135.gif'" alt="" width="135" height="135" />
      	</a><br/>
      	<em>${addOnProduct.addOnDesc}</em> 
				<a href="javascript:;" onClick="window.open('${urlPath}','','width=800,height=600,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no,left=50,top=50');return false;">
				<p>${aoproduct.productName}</p>
				</a>
        <c-rt:if test="${hasInventory!='true'}">
         <ul>
         	<li class="pdnmselect">&nbsp;</li>
         	<li><strong class="&nbsp;">已售完补货中</strong></li>
         </ul>
        </c-rt:if>
        <c-rt:if test="${hasInventory=='true'}">
        	<script language="javascript">
						haveInventory=true;
					</script>
        	<ul>
	         	<li class="pdnmselect">
	          	<select name="specNm" id="specNm_${nmStatus.index }">
		          	<option value="">选择商品属性</option>
		          	<c-rt:forEach items="${aoproduct.specifications}" var="spec" varStatus="status">
		           		<c-rt:set var="parasSpecInventory" value="${null}"/>
									<c-rt:set var="paramsSpecInventory" value="${pu:addToList('parasSpecInventory', spec.specificationId)}"/>
									<c-rt:set var="specInventorys" value="${pu:queryByHql('from SpecificationInventory where specId=?', paramsSpecInventory, null)}"/>
									${pu:listAdd('nmSpecInventorys', specInventorys[0].inventory)}
									<c-rt:set var="inventorySum">${inventorySum + specInventorys[0].inventory }</c-rt:set>
									<c-rt:choose>
										<c-rt:when test="${specInventorys[0].inventory == 0}">
											<option value="${spec.specificationId}" disabled="disabled">${spec.specificationName}-已售完</option>
										</c-rt:when>
										<c-rt:otherwise>
											<option value="${spec.specificationId}">${spec.specificationName}</option>
										</c-rt:otherwise>
	        				</c-rt:choose>
	        			</c-rt:forEach>
	        		</select>
	        	</li>
	        	<li><input class="addOnProductNm" id="addOnProductNm_${nmStatus.index }" name="addOnProductNm" type="checkbox" value="${addOnProduct.addOnProductId }_#spec#_1_${aoproduct.mainCategoryID}_6_<%=application.getContextPath() %>"><span>我要选购</span></li>
        	</ul>
        </c-rt:if>
      </div>
    </c-rt:forEach>
	</div>
</div>
<div class="pdnminfo">
	<strong>目前已选购 <em><b id="hasChecked">0</b></em>件</strong> (请任选<em> ${product.pickupQty } </em>件)
	<div class="pdnminfobt">
  	<c-rt:if test="${product.isDelete!='Q'}">
    	<a class="haveInventoryA" href="#" onclick="${toBuyMethod}" title="立即购买" style="cursor: pointer"><span class="bt-buy"></span></a>
     	<c-rt:if test="${product.productType!='1'}">
      	<a class="haveInventoryA" href="#" onclick="${toAddCartMethod}" title="加入购物车！" style="cursor: pointer"><span class="bt-cart"></span></a>
		 	</c-rt:if>
		 	<c-rt:if test="${product.productType=='1'}">
 	  	<div class="none-cart haveInventoryA" style="cursor: pointer"><span>加入购物车</span></div>
     </c-rt:if>
     <div class="none-buy haveNoInventoryA"><span>已售完补货中</span></div>
     <div class="none-cart haveNoInventoryA" style="cursor: pointer"><span>加入购物车</span></div>
  	</c-rt:if>
    <c-rt:if test="${product.isDelete=='Q'}">
			<div class="commingsoon"><span>即将开卖</span><%-- 开卖时间：TODO--%></div>
	  	<div class="none-cart" style="cursor: pointer"><span>加入购物车</span></div>
		</c-rt:if>
  </div>
</div>
<!-- mn --> 
<script language="javascript">
	var nmCount=0;
	var nmAt=0;
	$(function(){
		$('.addOnProductNm').each(function(){
			id=$(this).attr('id');
			index=id.replace('addOnProductNm_', '');
			if($(this).attr('checked')){
				$('#pdnmpinnerboxbg_'+index).attr('class', 'pdnmpinnerboxbg-f');
			}else{
				$('#pdnmpinnerboxbg_'+index).attr('class', 'pdnmpinnerboxbg');
			}
			$(this).click(function(){
				id=$(this).attr('id');
				index=id.replace('addOnProductNm_', '');
				if($('#specNm_'+index).attr('value')==''){
					alertDialog('讯息','请先选择属性');
					$(this).attr('checked', false);
				}else{
						nmCount=0;
						$('.addOnProductNm').each(function(){
							if($(this).attr('checked')){
								nmCount++;
							}	
						});
						if(nmCount>${product.pickupQty}){
							alertDialog('讯息', '已经选择${product.pickupQty}件');
							$(this).attr('checked', false);
							nmCount--;
						}else{
							$('#hasChecked').html(nmCount);
						}
				}
				if($(this).attr('checked')){
					$('#pdnmpinnerboxbg_'+index).attr('class', 'pdnmpinnerboxbg-f');
				}else{
					$('#pdnmpinnerboxbg_'+index).attr('class', 'pdnmpinnerboxbg');
				}
			});
		});
		$('.addOnProductNm').each(function(){
			if($(this).attr('checked')){
				nmCount++;
			}	
		});
		$('#hasChecked').html(nmCount);
	});
	function selectNm(index, specId){
		$('#specNm_'+index).attr('value', specId);
		$('#pdnmpinnerboxbg_'+index).attr('class', 'pdnmpinnerboxbg-f');
		$('#addOnProductNm_'+index).attr('checked', true);
		
				nmCount=0;
				$('.addOnProductNm').each(function(){
					if($(this).attr('checked')){
						nmCount++;
					}	
				});
				if(nmCount>${product.pickupQty}){
					alertDialog('讯息', '已经选择${product.pickupQty}件');
					$('#addOnProductNm_'+index).attr('checked', false);
					nmCount--;
				}else{
					
					$('#hasChecked').html(nmCount);
				}

		
	}
</script>